package com.sam.designpattern.proxy;

import java.util.Collection;

/**
 * @Author: Sam
 * @Date: 2022-08-03 11:08
 * @Description: 代理客户端
 */
public class Client {

    public static void main(String[] args) {
        //代理模式-懒加载示例
        UserManager userManager = new UserManager();
        Collection<UserModelApi> col = userManager.getUserByDeptId("100");
        //如果只是显示用户名称，则不需要重新查询数据库
        for (UserModelApi umApi : col) {
            System.out.println("用户编号：" + umApi.getUserId() + " 用户姓名：" + umApi.getName());
        }
        //如果访问非用户编号和用户姓名外的属性，那就会重新查询数据库
        for (UserModelApi umApi : col) {
            System.out.println("用户编号：" + umApi.getUserId() +
                    " 用户姓名：" + umApi.getName() +
                    " 所属部门：" + umApi.getDeptId() +
                    " 性别：" + umApi.getSex());
        }
    }
}
